package demo05;

/**
 * @author: WangPeng
 * @createTime: 2022/11/01 17:01
 * @description:
 * @version: v1.0
 */
public class TestDaemon {
    public static void main(String[] args) {
        DaemonDemo daemonDemo1 = new DaemonDemo("线程A");
        //设置t1为守护线程---当前台线程执行完毕后，守护线程也会结束
        daemonDemo1.setDaemon(true);
        daemonDemo1.start();

        DaemonDemo daemonDemo2 = new DaemonDemo("线程B");
//        设置t2为守护线程---当前台线程执行完毕后，守护线程也会结束
//        daemonDemo2.setDaemon(true);
        daemonDemo2.start();
    }
}
class DaemonDemo extends Thread{

    public DaemonDemo (String name){
        super(name);
    }
    @Override
    public void run() {
        for (int i = 0; i < 20; i++) {
            System.out.println(Thread.currentThread().getName()+"正在执行==="+i);
        }
    }
}
